package com.group3.controller.studentController;

import com.group3.domain.StudentWorkKey;
import com.group3.domain.Work;
import com.group3.pojo.*;
import com.group3.pojo.receive.WorkReceive;
import com.group3.service.StudentWorkService;
import com.group3.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(tags = "学生接口")
@RestController
@RequestMapping("/student/work")
@CrossOrigin
public class StudentWorkController {
    @Resource
    private StudentWorkService studentWorkService;

    @GetMapping(value = "/getWork")
    @ApiOperation(value = "根据学生id和作业状态查询学生相应的作业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "studentId", value = "学生id", required = true,
                    dataType = "String"),
            @ApiImplicitParam(name = "state", value = "作业状态", required = true,
                    dataType = "String"),
            @ApiImplicitParam(name = "type", value = "作业类型",
                    dataType = "String"),
            @ApiImplicitParam(name = "releaseTime", value = "作业发布时间",
                    dataType = "Date"),
            @ApiImplicitParam(name = "projectName", value = "项目名称",
                    dataType = "String"),
            @ApiImplicitParam(name = "workTheme", value = "作业主题",
                    dataType = "String"),
            @ApiImplicitParam(name = "teacherId", value = "实训教师id",
                    dataType = "String"),
            @ApiImplicitParam(name = "completionTime", value = "作业计划完成时间",
                    dataType = "Date"),
    })
    public Result<List<StudentWork>> getWork(WorkReceive workReceive) {

        Result result = studentWorkService.getWork(workReceive);

        return result;
    }

    @GetMapping(value = "/getDetail")
    @ApiOperation(value = "根据作业id查询详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "workId",value = "作业id",required = true,dataType = "Integer")
    })
    public Result<Work> getDetail(Integer workId) {

        Result result = studentWorkService.getDetail(workId);

        return result;
    }

    @PostMapping(value = "/submit"  )
    @ApiOperation(value = "学生提交作业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "workId", value = "作业id", required = true,
                    dataType = "String"),
            @ApiImplicitParam(name = "content", value = "作答详情", required = true,
                    dataType = "String"),
            @ApiImplicitParam(name = "state", value = "提交或保存", required = true,
                    dataType = "String"),
    })
    public Result submitWork(HttpServletRequest request, @RequestBody com.group3.domain.StudentWork submitReceive) {

        String token = request.getHeader("token");//获取token
        Result result = studentWorkService.submit(submitReceive,token);

        return result;
    }

    @GetMapping(value = "/getComment")
    @ApiOperation(value = "根据作业id查看教师批复内容")
    public Result<TeacherReply> getComment(StudentWorkKey studentWorkKey) {

        Result result = studentWorkService.getComment(studentWorkKey);

        return result;
    }


}
